package servlets;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import utils.MysqlDBConexion;
import bean.Alumno;

/**
 * Servlet implementation class Listar
 */
@WebServlet("/Listar")
public class Listar extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public Listar() {
        super();
        // TODO Auto-generated constructor stub
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		try {
			Connection cn=MysqlDBConexion.getConexion();
			String sql="select * from tb_alumno";
			PreparedStatement pst=cn.prepareStatement(sql);
			ResultSet rs=pst.executeQuery();
			ArrayList<Alumno> lista=new ArrayList<Alumno>();
			while (rs.next()) {
				Alumno usu=new Alumno(rs.getInt(1), rs.getString(2),rs.getString(3), rs.getInt(4),rs.getString(5),rs.getString(6),rs.getString(7));
				lista.add(usu);
			}
			req.setAttribute("listadito", lista);
			req.getRequestDispatcher("/Listar.jsp").forward(req, res);
		} catch (Exception e) {
		e.printStackTrace();
		}
		
	}

}
